Page({
  data: {},
  onLoad(option) {
    var that = this;
    that.setData({
      option: option
    })
  },
  formSubmit: function (e) {
    var that = this;
    var yuyue = e.detail.value;
    if (yuyue.name == "") {
      my.alert({
        title: '请填写您的姓名'
      });
      return false;
    }
    if (yuyue.tel == "") {
      my.alert({
        title: '请填写您的手机号'
      });
      return false;
    }
    if (yuyue.dizhi == "") {
      my.alert({
        title: '请填写您的地址'
      });
      return false;
    }
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(yuyue.tel)) {
      my.alert({
        title: '手机号有误！请重新填写'
      });
      return false;
    }
    my.httpRequest({
      url: 'https://zfbzzbj.chuangkegf.com/public/index.php/api/flink/bespeak',
      method: 'POST',
      data: {
        name: yuyue.name,
        phone: yuyue.tel,
        address: yuyue.dizhi,
        demand: yuyue.fuwu
      },
      dataType: 'json',
      success: function (res) {
        if (res.status == 200) {
          my.alert({
            title: res.data.msg, // alert 框的标题
            success: (res) => {
              my.navigateBack({
                delta: 2
              })
            },
          });
        } else {
          my.alert({ content: '网络错误！请稍后重试' });
        }
      },
      fail: function (res) {
        my.alert({ content: '网络错误！请稍后重试' });
      }
    });
  },
});
